package com.foton.bpc.all.remoting.netty.handler;

import com.foton.bpc.all.remoting.netty.adpect.HandlerAdpect;
import com.foton.bpc.all.remoting.netty.channel.impl.NettyChannel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author RenPu
 * @Date 2023/6/5 16:57
 * @Version 1.0
 * @Description: ChannelDuplexHandler,既可以为入，也可以为出  具体得逻辑处理器
 **/

@Slf4j
public class NettyLogicHandler extends ChannelDuplexHandler {

    private HandlerAdpect handlerAdpect;

    public NettyLogicHandler(HandlerAdpect handlerAdpect) {
        this.handlerAdpect = handlerAdpect;
    }

    /**
     * 入栈方法
     * @param ctx
     * @param msg
     * @throws Exception
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        log.info("NettyLogicHandler :::逻辑处理 LOGIC:::内容为：："+msg);

        //此处将数据下发到，Netty服务端的处理器
        handlerAdpect.onRecevice(new NettyChannel(ctx.channel()),msg);


        System.out.println("内容为：："+msg);
    }
}
